<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
 <a-row :gutter="24">
          <a-col :span="12">
        <a-form-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-select-yonghu :disabled="disableSubmit" :msg='yonghu'  v-decorator="['yongHuBiaoShi', validatorRules.yongHuBiaoShi]" :trigger-change="true" />
        </a-form-item>
         </a-col>
          <a-col :span="12">
        <a-form-item label="人员类别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag :disabled="disableSubmit"  type="list" v-decorator="['renYuanLeiBie', validatorRules.renYuanLeiBie]" :trigger-change="true" dictCode="gkak_rylb" placeholder="请选择人员类别"/>
        </a-form-item>
        </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
        <a-form-item label="编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input :disabled="disableSubmit"  v-decorator="[ 'bianHao', validatorRules.bianHao]" placeholder="请输入编号"></a-input>
        </a-form-item></a-col>
          <a-col :span="12">
        <a-form-item label="身份证号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input :disabled="disableSubmit"  v-decorator="[ 'shenFenZhengHao', validatorRules.shenFenZhengHao]" placeholder="请输入身份证号"></a-input>
        </a-form-item>
        </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
        <a-form-item label="通信地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input :disabled="disableSubmit"  v-decorator="[ 'tongXinDiZhi', validatorRules.tongXinDiZhi]" placeholder="请输入通信地址"></a-input>
        </a-form-item></a-col>
          <a-col :span="12">
        <a-form-item label="机构类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag :disabled="disableSubmit"  type="list" v-decorator="['jiGouType', validatorRules.jiGouType]" :trigger-change="true" dictCode="gkak_sbjglx" placeholder="请选择机构类型"/>
        </a-form-item></a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
        <a-form-item label="所属机构" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <!-- <a-input :disabled="disableSubmit"   v-decorator="[ 'suoShuJiGou', validatorRules.suoShuJiGou]" placeholder="请输入姓名"></a-input> -->
          <j-select-jigou :disabled="disableSubmit" :msg='jiGouIds' v-decorator="['suoShuJiGou', validatorRules.suoShuJiGou]" :trigger-change="true" />
          <!-- <j-select-depart :disabled="disableSubmit"  v-decorator="['suoShuJiGou', validatorRules.suoShuJiGou]" :trigger-change="true"/> -->
        </a-form-item>
        </a-col>
          <a-col :span="12">
        <a-form-item label="服务区域" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input :disabled="disableSubmit"  v-decorator="[ 'fuWuQuYu', validatorRules.fuWuQuYu]" placeholder="请输入服务区域"></a-input>
        </a-form-item>
        </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
        <a-form-item label="专长" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input :disabled="disableSubmit"  v-decorator="[ 'zhuanZhang', validatorRules.zhuanZhang]" placeholder="请输入专长"></a-input>
        </a-form-item>
        </a-col>
          <a-col :span="12">
        <a-form-item label="所属小组" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input :disabled="disableSubmit"  v-decorator="[ 'suoShuXiaoZu', validatorRules.suoShuXiaoZu]" placeholder="请输入所属小组"></a-input>
        </a-form-item>
         </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
        <a-form-item label="人员性质" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag :disabled="disableSubmit"  type="list" v-decorator="['renYuanXingZhi', validatorRules.renYuanXingZhi]" :trigger-change="true" dictCode="gkak_ryxz" placeholder="请选择人员性质"/>
        </a-form-item>
        </a-col>
          <a-col :span="12">
        <a-form-item label="附件" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-upload  :disabled="disableSubmit" v-decorator="['fuJian', validatorRules.fuJian]" :trigger-change="true"></j-upload>
        </a-form-item>
        </a-col>
        </a-row>
        
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JUpload from '@/components/jeecg/JUpload'
  import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"
  import JSelectJigou from '@/components/jeecgbiz/JSelectJigou'
  import JSelectYonghu from '@/components/jeecgbiz/JSelectYonghu'

  export default {
    name: "GkakRGongZuoRenYuanModal",
    components: { 
      JUpload,
      JSelectDepart,
      JDictSelectTag,
      JSelectYonghu,
      JSelectJigou
    },
    data () {
      return {
        form: this.$form.createForm(this),
        disableSubmit:false,
        jiGouIds:{},yonghu:{
        
      },
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          xingMing: {rules: [
          ]},
          renYuanLeiBie: {rules: [
          ]},
          bianHao: {rules: [
          ]},
          shenFenZhengHao: {rules: [
            {required: true, message: '请输入身份证号!'},
           {pattern:/^-?\d+\.?\d*$/, message: '请输入数字!'},
          ]},
          tongXinDiZhi: {rules: [
          ]},
          jiGouType: {rules: [
          ]},
          suoShuJiGou: {rules: [
          ]},
          fuWuQuYu: {rules: [
          ]},
          zhuanZhang: {rules: [
          ]},
          suoShuXiaoZu: {rules: [
          ]},
          renYuanXingZhi: {rules: [
          ]},
          fuJian: {rules: [
          ]},
        },
        url: {
          add: "/gkakRGongZuoRenYuan/add",
          edit: "/gkakRGongZuoRenYuan/edit",
        }
      }
    },
    created () {
    },
    methods: {
      jiGouId(record){
        this.$nextTick(() => {
          this.jiGouIds={
            id:record.suoShuJiGou,
            name:record.jiGouMingCheng
          } 
        })
    },
    yonghuIds(record){
      this.$nextTick(() => {
        this.yonghu ={
          name:record.realname,
          id:record.yongHuZhuJian
        } 
      })
    },
      add () {
        this.edit({});
      },
      edit (record) {
        
        this.jiGouId(record)
        this.yonghuIds(record)
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'xingMing','renYuanLeiBie','bianHao','shenFenZhengHao','tongXinDiZhi','jiGouType','suoShuJiGou','fuWuQuYu','zhuanZhang','suoShuXiaoZu','renYuanXingZhi','fuJian'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'xingMing','renYuanLeiBie','bianHao','shenFenZhengHao','tongXinDiZhi','jiGouType','suoShuJiGou','fuWuQuYu','zhuanZhang','suoShuXiaoZu','renYuanXingZhi','fuJian'))
      },

      
    }
  }
</script>